﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Model;
using BLL;

namespace GataBaseSys
{
    public partial class Login : System.Web.UI.Page
    {
        GataBaseBLL bll = new GataBaseBLL();
        UserBLL userbll = new UserBLL();
        SignIn info = new SignIn();
        UserInfo user = new UserInfo();
        protected void Page_Load(object sender, EventArgs e)
        {
            //SignIn info = Session["UserInfo"] as SignIn;
            //int id = info.SignInID;

        }

        protected void btnLogin_Click(object sender, EventArgs e)
        {
            if (this.txtUser.Text.Trim() == "" || this.txtPwd.Text.Trim() == ""||this.txtCode.Text.Trim()=="")
            {
                Response.Write("<script>alert('不能为空!')</script>");
            }
            else
            {if (txtCode.Text.ToLower() == (Session["checkCode"] + "").ToLower())
            {
                info.SignInName = this.txtUser.Text.Trim();
                info.SignInPwd = this.txtPwd.Text.Trim();
                if (userbll.GetGrand(info))
                {
                    Session["SignInName"] = info.SignInName;
                    Response.Redirect("ShangCha.aspx");

                }
                else if (userbll.GetGrandTwo(info))
                {
                    Session["SignInName"] = info.SignInName;
                    Response.Redirect("Index.aspx");
                }
                else
                {
                    Response.Write("<script>alert('登录失败')</script>");
                }
            }
            else
            {
                ClientScript.RegisterStartupScript(this.GetType(), "", "alert('验证码输入错误！')", true);
            }

            }
            
        }

        protected void btnRegister_Click(object sender, EventArgs e)
        {
            Response.Redirect("Register.aspx");
        }
    }
}